package Dao;

import ui.weatherInfo;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import static Dao.weatherDao.deleteWeather;

public class weatherInfoInsertDatabase {
    private static final String INSERT_STUDENT_SQL = "INSERT INTO weather_info (id,weather_data) VALUES (?, ?)";
    public static void main(String[] args) {

        weatherInfo weatherInfo=new weatherInfo();
        //插入数据库的操作

        insertWeatherInfo(weatherInfo);



        }
    public static void insertWeatherInfo(weatherInfo weatherInfo ) {
//        System.out.println(weatherInfo.getId());
////        System.out.println(weatherInfo.getInfo());



      //  weatherDao.deleteWeather();//-----------------------------
        //调用数据库的操作
      try (
            //  weatherDao.deleteWeather();------------这里面的方法在try---在里面和----在外面有什么区别
    Connection connection = DatabaseConnection.getConnection();
    PreparedStatement preparedStatement = connection.prepareStatement(INSERT_STUDENT_SQL)) {
        preparedStatement.setInt(1, weatherInfo.getId());
        preparedStatement.setString(2, weatherInfo.getInfo());
        int rowinserted = preparedStatement.executeUpdate();
        if (rowinserted > 0) {
            System.out.println("插入天气数据成功");}
      else {
            System.out.println("未找到指定的学生记录");
        }
    } catch (SQLException e) {

        e.printStackTrace();
    }


    }
}
//这里写的方法在weather中调用了
